<?php
Abstract class Action extends Object
{
	protected $user;
	protected $thing;
	protected $argArray;
	protected $permission = false;
	
	function __construct(&$user,$thing,$argArray = array())
	{
		parent::__construct();
		if($user instanceof User)
		{
			if(empty($thing))
			{
				return false;
			}
			$this->user = &$user;
			try{
			$thingClass = new ReflectionClass($thing);
			}
			catch(ReflectionException $e){
				exit("can't find appropriate thingClass!");
			}
			$this->thing = $thingClass->newInstance();
			$this->argArray = $argArray;
		}
		else
		{
			return false;
		}
	}
	
	public function doIt()
	{
		$this->verifyPermission();
		if($this->permission)
		{
			$result = $this->start();
			$this->end();
			return $result;			
		}
	}
	
	protected function verifyPermission()
	{
		$this->permission = $this->thing->verifyPermission($this->user);
	}
	
	protected function start()
	{
		return $this->thing->deal($this->user,$this->argArray);
	}
	
	protected function end()
	{
//		Log::record(xxx) record the action;
		return true;
	}
}

class ViewWeb extends Action
{
		
}

class LogIn extends Action
{
}
?>